/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function allInit(){
    FBinit();
    initdatapickers();
}

// datapickers per il form di ricerca avanzata
function initdatapickers() {
    var dates = $( "#data-from, #data-to" ).datepicker({
        dateFormat:"dd/mm/yy",
        onSelect: function( selectedDate ) {
            var option = this.id == "data-from" ? "minDate" : "maxDate",
            instance = $( this ).data( "datepicker" ),
            date = $.datepicker.parseDate(
                instance.settings.dateFormat ||
                $.datepicker._defaults.dateFormat,
                selectedDate, instance.settings );
            dates.not( this ).datepicker( "option", option, date );
        }
    });
}


function checkForm(){
    var isValidDate = true, isValidImp = true;
    var errors = "Errori nei seguenti campi:\n";
    
    var format ="dd/mm/yy";
    var df = $("#data-from").val();
    var dt = $("#data-to").val();
    if(!(isValidDate = validaform(df,dt))){
        errors = errors + "date\n";
        $("#data-from").val("");
        $("#data-to").val("");
    }
        
    var imp = $("#max-imp").val();
    if(!(isValidImp = !isNaN(imp))){
        errors = errors + "impressions\n";
        $("#max-imp").val("");
    }
        
    
    if(!(isValidDate && isValidImp))alert(errors);

    return (isValidDate && isValidImp);
}

function validaform(df,dt)
{
    var date1 = new Date(parseDate(df));
    var date2 = new Date(parseDate(dt));

    if (date1.getDate() >= date2.getDate()){
        return false ;
    }

    return true;

}